package com.sff.security {
	
	import com.sff.core.sff_internal;
	import com.sff.encrypt.Base64;
	
	import flash.system.Security;
	import flash.system.SecurityDomain;
	import flash.utils.ByteArray;		

	public class Security {

		private var _sandbox : SecurityDomain;
		public static var instance : Security;
		
		public function Security(  ) {
		}
		
		public static function start( ) : Security {
			if (instance == null)
				instance = new Security( );
			return instance;
		}
		
		public function get sandbox() : SecurityDomain {
			return _sandbox;
		}
		
		/**
		 * 	<secureDatas>
				<securedDomains>
					<domain>domain.com</domain>
					<domain>localhost</domain>
				</securedDomains>
			</secureDatas>
		 */
		private function execDatas( datas : XML ) : void {
			// open domains
			var domainList : XMLList = datas.securedDomains.domain;
			var d : String;
			for each ( var domainXml : XML in domainList ) {
				d = domainXml.text();
				flash.system.Security.allowDomain( d );
				//Firewall.allowDomain( d );
			}

			var crossList : XMLList = datas.policyDomains.domain; 
			for each ( domainXml in crossList ) {
				d = domainXml.text();
				flash.system.Security.loadPolicyFile( d );
			}
		}

		//sff_internal function run( datas : String ) : void {
		//flash.system.Security.exactSettings = false;
		
		//if( flash.system.Security.sandboxType == flash.system.Security.REMOTE ) 
		//_shellSandbox = SecurityDomain.currentDomain;
		
		//var ba : ByteArray = Base64.decodeToByteArray(datas);
		//var cipher : ICipher = getDefaultCipher( );
		//cipher.decrypt( ba );
		//ba.position = 0;
		//var result : String = ba.readUTFBytes( ba.bytesAvailable );
		
		//execDatas( XML( result ) );
		
		////Firewall.secureBatch( netSpooler );
		//}
				
		//private function getDefaultCipher() : ICipher {
		//	var i : ByteArray = new Crsecp( ).process( );
		//	var key : AESKey = new AESKey( i );
		//	var cbc : CBCMode = new CBCMode( key, new PKCS5( 128 ) );
		//	cbc.IV = i;
		//	return cbc;
		//}
	}
}
